//
//  HLMatchLabelCell.m
//  YueYue
//
//  Created by hulu001 on 2023/6/6.
//

#import "HLMatchLabelCell.h"

@interface HLMatchLabelCell ()

@property (nonatomic, strong) UIImageView *avatarView;
@property (nonatomic, strong) UILabel *nicknameLabel;
@property (nonatomic, strong) QMUIButton *selectedButton;

@end

@implementation HLMatchLabelCell


-(instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        [self setupView];
    }
    return self;
    
}

- (void)setupView {
    self.backgroundColor = UIColorClear;
    
    self.avatarView = [[UIImageView alloc] init];
    _avatarView.contentMode = UIViewContentModeScaleAspectFill;
    _avatarView.layer.masksToBounds = YES;
    _avatarView.layer.cornerRadius = 8;
    _avatarView.layer.borderColor = HLMainColor.CGColor;
    _avatarView.layer.borderWidth = 3;
    [self.contentView addSubview:_avatarView];
    [_avatarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(3, 3, 3, 3));
    }];
    
    self.nicknameLabel = [[UILabel alloc] qmui_initWithFont:UIFontMediumMake(16) textColor:UIColorWhite];
    _nicknameLabel.text = @"123";
    _nicknameLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:_nicknameLabel];
    [_nicknameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-12);
    }];
    
    self.selectedButton = [[QMUIButton alloc] init];
    [_selectedButton setImage:UIImageMake(@"match_normal_un_selected") forState:UIControlStateNormal];
    [_selectedButton setImage:UIImageMake(@"match_normal_selected") forState:UIControlStateSelected];
    [self.contentView addSubview:_selectedButton];
    [_selectedButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(24);
        make.top.mas_equalTo(8);
        make.right.mas_equalTo(-8);
    }];
}

- (void)setModel:(HLMatchLabelModel *)model
{
    _model = model;
    [_avatarView sd_setImageWithURL:[NSURL URLWithString:model.tagUrl] placeholderImage:[HLUIHelper avatarBigPlaceholder]];
    _nicknameLabel.text = model.tagName;
    
    if (model.isSelected){
        self.avatarView.layer.borderColor = UIColorWhite.CGColor;
        _selectedButton.selected = YES;
    } else {
        self.avatarView.layer.borderColor = HLMainColor.CGColor;
        _selectedButton.selected = NO;
    }
}


@end
